package TreeSet;

import java.util.Iterator;
import java.util.TreeSet;

public class TreeSemo {

	public static void main(String[] args) {
		TreeSet tre = new TreeSet();
		tre.add(new Student("jfj",55));
		tre.add(new Student("af",55));
		tre.add(new Student("gsavc",65));
		tre.add(new Student("eadf",25));
		tre.add(new Student("xczw",4));
		Iterator it =tre.iterator();
		while(it.hasNext()){
			Student a = (Student)it.next();
		System.out.println(a.getAge()+"......"+a.getName());
		}
		System.out.println("B".compareTo("A"));
	}
	

}
class Student implements Comparable{
	private String name;
	private int age;
	Student(String name,int age){
		this.name=name;
		this.age=age;
	}
	public int compareTo(Object obj){
		if (obj instanceof Student) {
			Student s = (Student) obj;
			if(this.age>s.age){
				return 1;
			}
			if(this.age==s.age){
				this.name.compareTo(s.name);
			}
		}
		return -1;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	
}